package com.view;

import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import com.adpter.IyrUserListAdapter;
import com.android.ocean.util.common.StringUtil;
import com.android.ocean.view.XListView;
import com.android.ocean.view.XListView.IXListViewListener;
import com.http.UserListTask;
import com.matang.R;
import com.modle.User;
import com.util.AppUtil;

/**
 * 
 * @author zhuwei可下拉加载的内容列表ListView,用于新闻列表展示
 * 
 */
public class XIyrListView extends BaseFrameLayout implements
		IXListViewListener,UserListTask.CallBack {
	ArrayList<User> dataList = new ArrayList<User>();
	int currentPage = 1;
	IyrUserListAdapter xListAdapter;
	XListView xlistView;
	String catID;// 获取内容的栏目ID
	String searType;// 搜索排序方式
	public XIyrListView(Context context) {
		super(context);
		init(context);
	}

	public XIyrListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public XIyrListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	private void init(Context context) {
		this.context = context;
		View view = LayoutInflater.from(context).inflate(
				R.layout.l_merge_xlist_conlist, this);
		xlistView = (XListView) view.findViewById(R.id.con_listview);
		xlistView.setPullLoadEnable(false);
		xlistView.setXListViewListener(this);
		xlistView.setRefreshTime(StringUtil.getFreshTime());
		loadingView = (View) view.findViewById(R.id.loading_view);

	}


	public void initData(ArrayList<User> list) {
		this.dataList=list;
		flushData();
		loadConList();
	}

	/**
	 * 加载数据
	 */
	private void loadConList() {
		new UserListTask(this).execute();
	}
    


	/**
	 * 此控件可以复用，当再次initConlistCatID或刷新前时需要先清除数据
	 */
	private void flushData() {
		currentPage = 1;
		xlistView.setAdapter(null);
		xlistView.setPullLoadEnable(false);
		xlistView.setRefreshTime(StringUtil.getFreshTime());
		xListAdapter = null;
		dataList.clear();
	}

	@Override
	public void onRefresh() {
		flushData();
		loadConList();
	}

	@Override
	public void onLoadMore() {
		currentPage++;
		loadConList();
	}

	@Override
	public void procError(String msg) {
		disLoading(loadingView);
		AppUtil.tsMsg(context, msg);
		
	}

	@Override
	public void procUserListData(ArrayList<User> dataList) {
		disLoading(loadingView);
		this.dataList=dataList;
		AppUtil.fillXListViewIyrListData(context, xlistView, dataList, xListAdapter, 0);
		
	}

}
